<script setup>
import { useUserStore, usePaintingStore } from '@/store/modules';
import { onHide } from '@dcloudio/uni-app';
import Toast from '@vant/weapp/dist/toast/toast';
import Dialog from '@vant/weapp/dist/dialog/dialog';
import { ref } from 'vue'
import projectConfig from '@/config/project/index.js'


const props = defineProps({
  item: Object,
})
const paintingStore = usePaintingStore()
const userStore = useUserStore();

const showFn = async () => {
  let path = ''
  switch (+props.item.modelTypeId) {

    case 1: // 文生图
      path = 'textGeneratePic'
      break;


    case 2: // 智能抠图
      path = 'imgMatting'
      break;


    case 3: // 变高清
      path = 'highQualityPic'
      break;


    case 4: // AI消除
      path = 'eliminate'
      break;


    case 5: // 图生图
      path = 'pictureGenneratePic'
      break;


    case 6: // 生成背景
      path = 'orgGenerationBgc'
      break;


    case 7: // 生成背景-v2
      path = 'generationBgImgSize'
      break;


    case 8: // AI扩图
      path = 'expansionPicture'
      break;

    case 10: // AI背景vip体验版
      path = 'vipOrgGenerationBgc'
      break;
    case 11: // AI背景vip体验版
      path = 'commandGenerationBgc'
      break;

  }
  paintingStore.clearImageObj()
  uni.setStorageSync('paint', props.item)
  try {
    await userStore.getUserInfo()
    uni.navigateTo({
      url: `/draw/${path}/index?item=${JSON.stringify(props.item)}`,
    })
  } catch (error) {

  }
}

const toPage = async () => {
  const white = [1, 5, 6, 7];
  const id = props.item.id;
  if (white.includes(id) && !uni.getStorageSync(JSON.stringify(id)) && projectConfig.painting.tipsAlert) {
    await Dialog.alert({
      title: '温馨提示',
      message: '此功能消耗算力过大，为了避免浪费，请学习后再用！学习请到【抖鑫鑫AI鑫世界直播间】',
      theme: 'round-button',
    })
    uni.setStorageSync(JSON.stringify(id), true)
  }
  showFn()
}
</script>

<template>
  <div class="box" @click="toPage">
    <div class="flex">
      <div class="iconBgc" :style="{ 'background-color': item.backColor }">
        <i :class="`iconfont ${item.imageUrl}`"></i>
      </div>
      <div class="rightText">{{ item.title }}</div>
    </div>
    <div class="contentText">
      {{ item.description }}
    </div>
  </div>
</template>


<style lang="less" scoped>
.box {
  box-sizing: border-box;
  width: 324rpx;
  height: 200rpx;
  background-color: var(--a-main-box-bg-color);
  border-radius: 30rpx;
  padding: 31rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 15rpx 10rpx 15rpx;
  // box-shadow: 5rpx 5rpx 16rpx rgba(0, 0, 0, 0.1);


  .flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .iconBgc {
    width: 50rpx;
    height: 50rpx;
    border-radius: 12rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32rpx;
    color: #ffffff
  }

  .rightText {
    flex: 1;
    text-align: left;
    margin-left: 20rpx;
    font-size: 30rpx;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--a-one-text-color)
  }

  .contentText {
    margin-top: 20rpx;
    font-size: 26rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    color: var(--a-two-text-color)
  }
}

/deep/.van-button--danger {
  background: var(--a-main-color) !important;
}
</style>